package gamesolitaire;


import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
public class Frame extends JFrame {
        
	 /**
	  * Required for serializable interface  
	  */
    private static final long serialVersionUID = 1L;
    private Board board;
    private Canvas canvas;

    public Frame(Board board,Canvas canvas) {
            super("BomSolitaire");
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.setSize(390, 415);
            this.build();
            this.board = board;
          	this.canvas = canvas;
    }
    
    public void build() {
    		MyActionListener mylistener = new MyActionListener();
            // Create menu bar
            JMenuBar menuBar = new JMenuBar();
            this.setJMenuBar(menuBar);
            
            // Create file menu
            JMenu fileMenu = new JMenu("File");
            menuBar.add(fileMenu);
            
            // create new login item 
            JMenuItem loginItem = new JMenuItem("Login");
            fileMenu.add(loginItem);
            loginItem.addActionListener(mylistener);
            loginItem.setActionCommand("Login");
            
            // create new register item
            JMenuItem regItem = new JMenuItem("Register");
            fileMenu.add(regItem);
            regItem.addActionListener(mylistener);
            regItem.setActionCommand("Reg");
            
            // create new game item
            JMenuItem newItem = new JMenuItem("New game");
            fileMenu.add(newItem);
            fileMenu.addSeparator();
            newItem.addActionListener(mylistener);
            newItem.setActionCommand("New");
            newItem.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK));
            
            // Create exit item
            JMenuItem exitItem = new JMenuItem("Exit");
            fileMenu.add(exitItem);
            exitItem.addActionListener(mylistener);
            exitItem.setActionCommand("Exit");
            
            // create a new menu options
            JMenu optionMenu = new JMenu("Option");
            menuBar.add(optionMenu);
            
            //create a option switch icon
            JMenuItem iconItem = new JMenuItem ("Icons");
            optionMenu.add(iconItem);
            iconItem.addActionListener(mylistener);
            iconItem.setActionCommand("Icons");
            
            // create a option undo
            JMenuItem undoItem = new JMenuItem("Undo");
            optionMenu.add(undoItem);
            undoItem.addActionListener(mylistener);
            undoItem.setActionCommand("Undo");
            undoItem.setAccelerator(KeyStroke.getKeyStroke('U', InputEvent.CTRL_DOWN_MASK));
            
            // create a new menu Help
            JMenu helpMenu = new JMenu("Help");
            menuBar.add(helpMenu);
           
            
            // create info
            JMenuItem infoItem = new JMenuItem ("Info");
            helpMenu.add(infoItem);
            infoItem.addActionListener(mylistener);
            infoItem.setActionCommand("Info");
    }
    	class MyActionListener implements ActionListener{
    			@Override
				public void actionPerformed(ActionEvent arg0) {
					//System.out.println("button pressed");
					switch (arg0.getActionCommand()){
					case "New":
								System.out.println("New Pressed");
								break;
					case "Undo":
								//System.out.println("Undo Pressed");
								board.undo();
								canvas.repaint();
								break;
					case "Login":
								System.out.println("Login Pressed");
								break;
					case "Reg":
								System.out.println("Register Pressed");
								break;
					case "Info":
								System.out.println("Info Pressed");
								break;
					case "Icons":
								System.out.println("Icon Pressed");
								break;
					case "Exit":
								System.out.println("Exit Pressed");
								break;
					}
					
				}
    	}

}